﻿using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;

public class CustomerChangeModel : MonoBehaviour
{
    public GameObject[] hairGos;
    public GameObject[] faceGos;
    public GameObject[] clothingUpGos;
    public GameObject[] clothingDownGos;
    public GameObject[] shoesGos;

    //Texture2D texture2D = null;
    //private Material mat = null;
    //Color color = new Color();
    private void Awake()
    {
        Init();
    }
    void Start()
    {
        //RandomColor();
        //SetMaterials();
        //SpawnModels();
        //Debug.Log();
    }
    void Init()//初始化，每个组的模型先全部隐藏
    {
        foreach (var item in hairGos)
        {
            item.gameObject.SetActive(false);
        }
        foreach (var item in faceGos)
        {
            item.gameObject.SetActive(false);
        }
        foreach (var item in clothingUpGos)
        {
            item.gameObject.SetActive(false);
        }
        foreach (var item in clothingDownGos)
        {
            item.gameObject.SetActive(false);
        }
        foreach (var item in shoesGos)
        {
            item.gameObject.SetActive(false);
        }
    }

    int RandomIndex(int Length)//根据每个组的长度，取一个随机索引
    {
        return Random.Range(0, Length);
    }
    void ShowModels(GameObject[] gos)//将组里面对应索引的模型，显示出来
    {
        int index = RandomIndex(gos.Length);
        gos[index].gameObject.SetActive(true);
        //gos[index].GetComponent<SkinnedMeshRenderer>().material = mat;
    }
    void SpawnModels()//五大组各显示一个模型，作为一个完整的角色展示
    {
        ShowModels(hairGos);
        ShowModels(faceGos);
        ShowModels(clothingUpGos);
        ShowModels(clothingDownGos);
        ShowModels(shoesGos);
    }
    //void RandomColor()//随机颜色
    //{
    //    float colorR = Random.Range(0f, 1f);
    //    float colorG = Random.Range(0f, 1f);
    //    float colorB = Random.Range(0f, 1f);
    //    color = new Color(colorR, colorG, colorB, 1);
    //}
    //void SetMaterials()//重新设置材质
    //{
    //    mat = new Material(Shader.Find("ASE/ASE-LitEmission"));
    //    //mat = new Material(Shader.Find("Mobile/Diffuse"));
    //    texture2D = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Art/testAssets/character/characters.png", typeof(Texture2D));
    //    mat.SetTexture("_mainTexture",texture2D);
    //    mat.SetColor("_Color", color);
    //}
  
}
